package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Paymentaccount;
import com.ruoyi.system.service.IPaymentaccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付账号管理Controller
 * 
 * @author ruoyi
 * @date 2022-09-23
 */
@Controller
@RequestMapping("/system/paymentaccount")
public class PaymentaccountController extends BaseController
{
    private String prefix = "system/paymentaccount";

    @Autowired
    private IPaymentaccountService paymentaccountService;

    @RequiresPermissions("system:paymentaccount:view")
    @GetMapping()
    public String paymentaccount()
    {
        return prefix + "/paymentaccount";
    }

    /**
     * 查询支付账号管理列表
     */
    @RequiresPermissions("system:paymentaccount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Paymentaccount paymentaccount)
    {
        startPage();
        List<Paymentaccount> list = paymentaccountService.selectPaymentaccountList(paymentaccount);
        return getDataTable(list);
    }

    /**
     * 导出支付账号管理列表
     */
    @RequiresPermissions("system:paymentaccount:export")
    @Log(title = "支付账号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Paymentaccount paymentaccount)
    {
        List<Paymentaccount> list = paymentaccountService.selectPaymentaccountList(paymentaccount);
        ExcelUtil<Paymentaccount> util = new ExcelUtil<Paymentaccount>(Paymentaccount.class);
        return util.exportExcel(list, "支付账号管理数据");
    }

    /**
     * 新增支付账号管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存支付账号管理
     */
    @RequiresPermissions("system:paymentaccount:add")
    @Log(title = "支付账号管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Paymentaccount paymentaccount)
    {
        return toAjax(paymentaccountService.insertPaymentaccount(paymentaccount));
    }

    /**
     * 修改支付账号管理
     */
    @RequiresPermissions("system:paymentaccount:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Paymentaccount paymentaccount = paymentaccountService.selectPaymentaccountById(id);
        mmap.put("paymentaccount", paymentaccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付账号管理
     */
    @RequiresPermissions("system:paymentaccount:edit")
    @Log(title = "支付账号管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Paymentaccount paymentaccount)
    {
        return toAjax(paymentaccountService.updatePaymentaccount(paymentaccount));
    }

    /**
     * 删除支付账号管理
     */
    @RequiresPermissions("system:paymentaccount:remove")
    @Log(title = "支付账号管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paymentaccountService.deletePaymentaccountByIds(ids));
    }

    /**
     * 移动端添加方法
     * @param account
     * @return
     */
    @PostMapping( "/myadd")
    @ResponseBody
    public AjaxResult myadd(@RequestParam("account") String account){
        Paymentaccount paymentaccount=new Paymentaccount();
        paymentaccount.setAccount(account);
        paymentaccountService.insertPaymentaccount(paymentaccount);
        return  success();
    }

    /**
     * 移动端查询风险账号
     * @param account 账号
     * @return 是否是风险账号 TRUE表示是风险账号，FALSE表示不是风险账号
     */
    @PostMapping( "/mygetItem")
    @ResponseBody
    public AjaxResult mygetitem(@RequestParam("account") String account){
        Paymentaccount paymentaccount=new Paymentaccount();
        paymentaccount.setAccount(account);
        List<Paymentaccount> paymentaccounts = paymentaccountService.selectPaymentaccountList(paymentaccount);
        return success(paymentaccounts.size()>0);
    }
}
